import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { AccManageConst } from "src/consts/acc_manage_const";
import { PopupName } from "src/consts/popup_const";
@Component({})
export default class AccOrgPanel extends MyVue {
    name: string = 'AccOrgPanel';
    formData: any;
    selectData: any;
    footerFlag: boolean = true;
    selection: any[];
    titles: String[];
    changeFlag: Boolean;

    beforeCreate(): void {
    }

    initData(that?: any): void {
        that.formData = WLStore().state.org;
        if (WLStore().state.accManage.type == "edit") {
            that.selectData = WLStore().state.accManageShow;
        } else if (WLStore().state.accManage.type == "add") {
            that.selectData = WLStore().state.accManageAdd;
        }
    }

    mounted(): void {
    }

    editOrg(): void {
        if (this.changeFlag) {
            var orgArr: any = []
            for (let i = 0; i < this.selection.length; i++) {
                orgArr[i] = {}
                orgArr[i].id = this.selection[i].id
                orgArr[i].name = this.selection[i].name
            }
            if (WLStore().state.accManage.type == "edit") {
                WLCommit(AccManageConst.CommitShowDept, orgArr)
            } else if (WLStore().state.accManage.type == "add") {
                WLCommit(AccManageConst.CommitAddDept, orgArr)
            }
        } else {
            WLLib.panel(PopupName.Acc_Org_Panel).close();
        }
    }

    rightChange(val: any): void {
        this.selection = val
        this.changeFlag = true
    }

    leftChange(val: any): void {
        this.selection = val
        this.changeFlag = true
    }
}